package com.dong.dao;

import com.dong.entity.Account;
import com.dong.entity.Orders;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Repository;

import java.util.List;
@Repository("accountDao")
public interface IAccountDao {
    @Select("select * from account")
    List<Account> findAll();

    @Insert("insert into account (name,money) values (#{name},#{money})")
    void saveAccount(Account account);

    @Delete("delete from account where id=#{id}")
    void delete(int id);

    @Update("update account set name=#{name},money=#{money} where id=#{id}")
    void update(Account account);

    @Select("select * from account where name=#{name}")
    Account checkName(String name);

    @Select("select * from account where id=#{id}")
    Account findById(int id);

    @Select("select * from account where name like concat('%',#{name},'%')")
    List<Account> findByName(String name);

    @Select("select * from account where id=#{id}")
    @Results(value = {
            @Result(id = true ,property = "id",column = "id"),
            @Result(property = "name",column = "name"),
            @Result(property = "money",column = "money"),
//            @Result(property = "o_name",column = "o_name"),
//            @Result(property = "o_date",column = "o_date"),
//            @Result(property = "o_money",column = "o_money"),
            @Result(column = "id",property = "orders",javaType = Orders.class,
            one=@One (select = "com.dong.dao.IOrdersDao.findOrdersByaid")),
            @Result(column = "id",property = "cardsList",javaType = java.util.List.class,
            many = @Many(select = "com.dong.dao.ICardsDao.findAllCardsByaid"))
    })
    Account findAllByaid(int id);




}
